package com.leyou.auth.controller;

import com.leyou.auth.Servcie.AuthService;
import com.leyou.auth.Servcie.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public ResponseEntity<Void>  login(@RequestParam("username")String username,
                                       @RequestParam("password")String psssword,
                                       HttpServletResponse response){
        userService.login(username,psssword,response);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/logout")
    public ResponseEntity<Void>  logout(HttpServletRequest request,HttpServletResponse response){
        userService.logout(request,response);
        return ResponseEntity.noContent().build();
    }
}
